/**
 * @param {String} url
 * @param {String} params
 * @param {Function} headersFn 
 * @returns Promise  
 */
function  get(url,params,headerFn)
{
    return new Promise((resolve,reject)=>{
        const xhr = new XMLHttpRequest
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4)
            {
                if(xhr.status == 200)
                {
                    let res = JSON.parse(xhr.responseText)
                    resolve(res)
                }
                else
                {
                    reject(xhr.status)
                }
            }
        }
        xhr.open("get",`${url}?${params}`)
        if(headerFn) headerFn(xhr)
        xhr.send(null)
    })
}




/**
 * @param {String} url
 * @param {String} params
 * @param {Function} headersFn 
 * @returns Promise  
 */
function  post(url,params,headerFn)
{
    return new Promise((resolve,reject)=>{
        const xhr = new XMLHttpRequest
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4)
            {
                if(xhr.status == 200)
                {
                    let res = JSON.parse(xhr.responseText)
                    resolve(res)
                }
                else
                {
                    reject(xhr.status)
                }
            }
        }
        xhr.open("post",url)
        xhr.setRequestHeader("content-type","application/x-www.form-urlencoded")
        if(headerFn) headerFn(xhr)
        xhr.send(params)
    })
}